<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <input type="text" v-model="p.id" placeholder="id" readonly>
    <input type="text" v-model="p.title" placeholder="商品名称">
    <input type="text" v-model="p.price" placeholder="商品价格">
    <input type="text" v-model="p.saleCount" placeholder="商品库存">
    <input type="button" value="修改" @click="update()">
</div>

<script src="js/vue.js"></script>
<script src="js/axios.min.js"></script>
<script>
    let v= new Vue({
        el:"div",
        data:{
            p:{
                id:"",
                title:"",
                price:"",
                saleCount:"",
            }
        },
        created(){
            let id = location.search.split("=")[1];
            axios.get("/selectById?id="+id).then(function (response){
                v.p=response.data;
            })
        },
        methods:{
            update(){
                axios.post("/update",v.p).then(function (response){
                    if (response.data==1){
                        alert("修改失败: 请您输入完整商品信息修改")
                        location.reload()
                        return;
                    }
                    alert("修改成功!")
                    location.href="/list.html"
                })
            }
        }
    })
</script>

</body>
</html>